/*******************************************************************************
 * Copyright (c) 2012 AwOiSoAk.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     $AwOiSoAk - initial API and implementation
 ******************************************************************************/
package com.awoisoak.dundeeguide;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import com.google.android.maps.OverlayItem;
import com.madsa.AugmentedCompass.BrujulaAumentada;

@SuppressWarnings("rawtypes") 
public class MyItemizedOverlay extends com.google.android.maps.ItemizedOverlay {
	
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	static Context mcontext;
	String coord =null;

	public MyItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}
	
	public MyItemizedOverlay(Drawable defaultMarker,Context context) {
		super(boundCenterBottom(defaultMarker));
		mcontext = context;
		
	}
	
	

	
	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
	    populate();
	}
	
	
	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		
		final OverlayItem itemClicked = mOverlays.get(index);

		final String title = itemClicked.getTitle();
		final String coord = itemClicked.getSnippet();

		AlertDialog.Builder builder = new AlertDialog.Builder(mcontext);
		
	    	builder.setTitle(title)
    				.setMessage("Do you want to use the compass to get here?")
    				.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
    					public void onClick(DialogInterface dialog, int id) {
    	                
    						Intent i = new Intent(mcontext, BrujulaAumentada.class);    					
   					
    						i.putExtra("destineDescription", "    "+title);
    						i.putExtra("destineLocation", coord);
    						i.putExtra("imageName","ar_destino");
    						mcontext.startActivity(i);
    	        	   
    	        	   
    					}	
    				})
    				.setNegativeButton("No", new DialogInterface.OnClickListener() {
    					public void onClick(DialogInterface dialog, int id) {
    						dialog.cancel();
    					}
    				});
		
			
    	AlertDialog alertList = builder.create();
    	alertList.show();
    	
        return true;
		}
		
		
	

	
	
	
}
